package br.mg.bhe.ftpobre.util;

import java.io.File;

import br.mg.bhe.ftpobre.fs.LocalFile;
import br.mg.bhe.ftpobre.gui.MainFrame;

/**
 * 
 * @author Aureliano
 */
public final class LocalFileUtil {

	private LocalFileUtil() {
		super();
	}
	
	public static LocalFile getSelectedFile() {
		int row = MainFrame.getInstance().getTableLocalFiles().getSelectedRow();
        if (row == -1) {
        	return null;
        }
        
        return (LocalFile) MainFrame.getInstance()
        		.getTableLocalFiles().getModel().getValueAt(row, 1);
	}
	
	public static File getPreferenceFolder() {
		return getFolder("preferences");
	}
	
	public static File getCacheFolder() {
		return getFolder("cache");
	}
	
	public static File getLogFolder() {
		return getFolder("log");
	}
	
	private static File getFolder(String folderName) {
		String path = new File("").getAbsolutePath() + "/" + folderName;
        File folder = new File(path);
        if (!folder.exists()) {
        	if (!folder.mkdir()) {
        		throw new RuntimeException(
        				"Não foi possível criar diretório " + folder.getAbsolutePath());
        	}
        }
        
        return folder;
	}
}